package com.loopy.servlet.request;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class CheckServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        System.out.println("CheckServlet被调用");
        String username = request.getParameter("username");
        //如果是同一个request对象(请求转发不会产生新的request对象)，那么可以在不同的servlet中使用getAttribute()
        if("tom".equals(username)){
            request.setAttribute("role","管理员");
        }else{
            request.setAttribute("role","普通用户");
        }
        //1./manager写的是要转发的servlet的url
        //2./会被解析成http://localhost:8080/ServletHomework
        // 3.forward把当前request,response原封不动的
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/manager");
        requestDispatcher.forward(request,response);
    }
}
